package com.nus.servlets;

import com.nus.beans.ProjectRemark;
import com.nus.beans.UserEvaluation;
import com.nus.database.ProjectsDBManager;
import com.nus.database.UserInfoDBManager;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;

/**
 * Created by IntelliJ IDEA.
 * User: dell
 * Date: 11/4/12
 * Time: 10:38 AM
 * To change this template use File | Settings | File Templates.
 */
public class UpdateUserEvaluationsServlet extends AbstractServlet{
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String userEvaluationId = request.getParameter("userEvaluationId");
        String evaluation = request.getParameter("evaluation");

        int userEvaluationIdInt = Integer.parseInt(userEvaluationId);

        Connection connection = getUserDatabaseConnection(request);
        UserInfoDBManager userInfoDBManager = new UserInfoDBManager(connection);

        UserEvaluation userEvaluation = new UserEvaluation();
        userEvaluation.setId(userEvaluationIdInt);
        userEvaluation.setEvaluation(evaluation);

        userInfoDBManager.updateUserEvaluation(userEvaluation);

        UserEvaluation updatedEvaluation = userInfoDBManager.getUserEvaluation(userEvaluationIdInt);

        request.setAttribute("targetUserId", updatedEvaluation.getUserId());

        RequestDispatcher dispatcher = request.getRequestDispatcher("viewUserEvaluations.do");
        dispatcher.forward(request, response);
    }
}
